package cp3120.ucm.client;

import cp3120.dao.DAOFactory;
import cp3120.model.Flight;
import cp3120.ucm.UCController;
import cp3120.view.FlightView;
import cp3120.view.MainUI;

/**
 *
 * @author Adam Scarr <scarr.adam@gmail.com>
 * PRECONDITION: The User is at the flight veiw  <br>
 * POST-CONDITION: The sytem has added the flights from the User's purchase to the database <br>
 * USER: A customer wishing to remove a flight<br>
 * 1. System gets the flight from the veiw<br>
 * 2. System removes the flight from the database<br>
 * 3. System closes flight veiw<br>
 * 4. System updates the mainUI<br>
 */
public class UCDeleteFlight implements UCController {
    private FlightView view;

    /**
     * Constructor
     * @param view FlightVeiw that contains the Flight to be deleted
     */
    public UCDeleteFlight(FlightView view) {
        this.view = view;
    }

    /**
     * Runs the UC
     */
    public void run() {
        Flight flight = view.getFlight();

        DAOFactory.getFlightDAO().deleteFlight(flight);

        view.dispose();
        MainUI.getInstance().update();
    }

}
